﻿<demo:DemoViewBase x:Name="_root"
	x:Class="ToolBarDemo.ToolBarDemoView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:ToolBarDemo"
	xmlns:demo="clr-namespace:DemoSupport;assembly=DemoSupport"
	xmlns:sys="clr-namespace:System;assembly=mscorlib">
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="1*"/>
			<ColumnDefinition Width="Auto"/>
			<ColumnDefinition Width="2*"/>
		</Grid.ColumnDefinitions>

		<FlowDocumentScrollViewer DataContext="{Binding ElementName=_root}" VerticalScrollBarVisibility="Auto">
			<FlowDocument>
				<Paragraph>
					<Span Style="{DynamicResource Heading1}">Tool Bar Service</Span>
				</Paragraph>
				<Paragraph>
					The shell provides a tool bar service. This service is an implementation of the
					<Span Style="{DynamicResource Code}">IToolBarService</Span> interface, and it allows module developers to easily add
					tool bars and tool bar items to the shell. It is used in conjunction with the command service, which allows you to wrap
					either a CAB or WPF command instance for consumption by the tool bar service.
				</Paragraph>
				<Paragraph>
					The tool bar service automatically adds tool bars for you based on the target site name of the tool bar items you add.
					If a tool bar already exists with the specified site name, it will be used. Otherwise, a new tool bar will be added for
					you.
				</Paragraph>
				<Paragraph>
					The shell also includes the ability for users to turn tool bars on and off. This is achieved either by right-clicking
					the tool bar tray area, or by using the <Italic>View / Toolbars</Italic> menu item.
				</Paragraph>
				<Paragraph>
					The tool bar service provides the same grouping and sorting behavior for tool bar items as it does for menu items. In
					fact, it's using the same code behind the scenes.
				</Paragraph>
			</FlowDocument>
		</FlowDocumentScrollViewer>

		<GridSplitter Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>

		<demo:DemoSet Grid.Column="2">
			<demo:DemoSet.CommandBindings>
				<CommandBinding Command="{x:Static local:ToolBarDemoView.Example1AddToolBarItem}" CanExecute="Example1AddToolBarItem_CanExecute" Executed="Example1AddToolBarItem_Executed"/>
				<CommandBinding Command="{x:Static local:ToolBarDemoView.Example1CleanUp}" CanExecute="Example1CleanUp_CanExecute" Executed="Example1CleanUp_Executed"/>

				<CommandBinding Command="{x:Static local:ToolBarDemoView.Example2AddToolBarItem}" CanExecute="Example2AddToolBarItem_CanExecute" Executed="Example2AddToolBarItem_Executed"/>
				<CommandBinding Command="{x:Static local:ToolBarDemoView.Example2CleanUp}" CanExecute="Example2CleanUp_CanExecute" Executed="Example2CleanUp_Executed"/>

				<CommandBinding Command="{x:Static local:ToolBarDemoView.Example3AddToolBarItems}" CanExecute="Example3AddToolBarItems_CanExecute" Executed="Example3AddToolBarItems_Executed"/>
				<CommandBinding Command="{x:Static local:ToolBarDemoView.Example3CleanUp}" CanExecute="Example3CleanUp_CanExecute" Executed="Example3CleanUp_Executed"/>
			</demo:DemoSet.CommandBindings>

			<demo:Demo Title="Adding a Tool Bar Item to an Existing Tool Bar">
				<demo:Demo.Description>
					This example demonstrates how to add a tool bar item to an existing tool bar.
				</demo:Demo.Description>
				<demo:Step Title="Add the tool bar item" Command="{x:Static local:ToolBarDemoView.Example1AddToolBarItem}">
					<demo:Step.Header>
						This step adds a new tool bar item to the Edit tool bar.
					</demo:Step.Header>
					<demo:Step.Code>
						<sys:String xml:space="preserve">ICommand command = _commandService.CreateCommand(WorkItem.Commands["ToolBarItem"], "Tool Bar Item", null);
_item = _toolBarService.AddButtonItem(ExtensionSites.ToolBar.Edit.Name, command, null, null);</sys:String>					</demo:Step.Code>
				</demo:Step>
				<demo:Step Title="Clean up" Command="{x:Static local:ToolBarDemoView.Example1CleanUp}">
					<demo:Step.Header>
						This step removes the tool bar item added in the above step.
					</demo:Step.Header>
					<demo:Step.Code>
						<sys:String xml:space="preserve">_toolBarService.Remove(_item);
_item = null;</sys:String>					</demo:Step.Code>
				</demo:Step>
			</demo:Demo>

			<demo:Demo Title="Adding a Tool Bar Item to a new Tool Bar">
				<demo:Demo.Description>
					This example demonstrates how to add a tool bar item to a new tool bar.
				</demo:Demo.Description>
				<demo:Step Title="Add the tool bar item" Command="{x:Static local:ToolBarDemoView.Example2AddToolBarItem}">
					<demo:Step.Header>
						This step adds a new tool bar item to a new tool bar.
					</demo:Step.Header>
					<demo:Step.Code>
						<sys:String xml:space="preserve">ICommand command = _commandService.CreateCommand(WorkItem.Commands["ToolBarItem"], "Tool Bar Item", null);
_itemInNewToolBar = _toolBarService.AddButtonItem("Some Tool Bar", command, null, null);</sys:String>					</demo:Step.Code>
					<demo:Step.Footer>
						After executing this step, try right-clicking the tool bar tray area. You'll see the new tool bar listed there.
					</demo:Step.Footer>
				</demo:Step>
				<demo:Step Title="Clean up" Command="{x:Static local:ToolBarDemoView.Example2CleanUp}">
					<demo:Step.Header>
						This step removes the tool bar item added in the above step.
					</demo:Step.Header>
					<demo:Step.Code>
						<sys:String xml:space="preserve">_toolBarService.Remove(_itemInNewToolBar);
_itemInNewToolBar = null;</sys:String>					</demo:Step.Code>
				</demo:Step>
			</demo:Demo>

			<demo:Demo Title="Grouping and Sorting Tool Bar Items">
				<demo:Demo.Description>
					This example demonstrates how tool bar items can be grouped and sorted within their tool bar.
				</demo:Demo.Description>
				<demo:Step Title="Add the tool bar items" Command="{x:Static local:ToolBarDemoView.Example3AddToolBarItems}">
					<demo:Step.Header>
						This step adds a number of tool bar items that are grouped and sorted.
					</demo:Step.Header>
					<demo:Step.Code>
						<sys:String xml:space="preserve">ICommand command1 = _commandService.CreateCommand(WorkItem.Commands["ToolBarItem"], "Tool Bar Item 1", null);
ICommand command2 = _commandService.CreateCommand(WorkItem.Commands["ToolBarItem"], "Tool Bar Item 2", null);
ICommand command3 = _commandService.CreateCommand(WorkItem.Commands["ToolBarItem"], "Tool Bar Item 3", null);
ICommand command4 = _commandService.CreateCommand(WorkItem.Commands["ToolBarItem"], "Tool Bar Item 4", null);
_item1 = _toolBarService.AddButtonItem("Sorted and Grouped Bar", command1, 0, 0);
_item3 = _toolBarService.AddButtonItem("Sorted and Grouped Bar", command3, 0, 2);
_item2 = _toolBarService.AddButtonItem("Sorted and Grouped Bar", command2, 0, 1);
_item4 = _toolBarService.AddButtonItem("Sorted and Grouped Bar", command4, 1, 0);</sys:String>					</demo:Step.Code>
					<demo:Step.Footer>
						After executing this step, notice how the shell has correctly ordered and separated the items.
					</demo:Step.Footer>
				</demo:Step>
				<demo:Step Title="Clean up" Command="{x:Static local:ToolBarDemoView.Example3CleanUp}">
					<demo:Step.Header>
						This step removes the tool bar items added in the above step.
					</demo:Step.Header>
					<demo:Step.Code>
						<sys:String xml:space="preserve">_toolBarService.Remove(_item1);
_toolBarService.Remove(_item2);
_toolBarService.Remove(_item3);
_toolBarService.Remove(_item4);
_item1 = null;
_item2 = null;
_item3 = null;
_item4 = null;</sys:String>					</demo:Step.Code>
				</demo:Step>
			</demo:Demo>
		</demo:DemoSet>
	</Grid>
</demo:DemoViewBase>
